package org.fall.view.controller;

import org.fall.view.model.ResultEntity;
import org.fall.view.model.dto.MemberUserDTO;
import org.fall.view.service.MemberUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * 用户操作控制器
 * @author sprogFall
 * @since 2021/4/12 15:06
 */
@Controller
@RequestMapping("/member/")
public class MemberUserController {

    @Resource
    private MemberUserService memberUserService;

    /**
     * 登录操作
     * @param dto dto
     * @param session session
     * @return 登录结果
     */
    @PostMapping("login")
    @ResponseBody
    public ResultEntity login(@RequestBody MemberUserDTO dto, HttpSession session) {
        return memberUserService.login(dto, session);
    }

    /**
     * 退出登录
     * @param session session
     * @return 前往登录页面
     */
    @GetMapping("logout")
    public String logout(HttpSession session) {
        session.invalidate();
        return "login";
    }
}
